<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro/easyui.css"/>
<title>门诊登记页面</title>
</head>
<body>
<script type="text/javascript">
		$(function(){
			$('#mediccard-tab').datagrid({
			    url:'selectAll-clinic',
			    pagination:true,                           
			    pageNumber:1,
			    pageSize:3,
			    pageList:[2,3],
			    columns:[[
			            {field:'clinicId',title:'',width:50,checkbox:true},
			    	 	{field:'cliniccardId',title:'医疗卡号',width:160},
						{field:'clinicName',title:'病人姓名',width:110},
						{field:'clinicSex',title:'性别',width:100},
						{field:'clinicIdnumber',title:'身份证号',width:170},
						{field:'clinicRemainmoney',title:'剩余金额',width:172},
						{field:'clinicTime',title:'办卡时间',width:188,formatter:comFormatDate}
						/* {field:'offi',title:'操作',width:158,
							formatter:function(value,row,index){
								 //输入框
								// var str="<input  class='easyui-switchbutton'/>"
							    //按钮
								 var str2="<a  class='easyui-linkbutton' onclick='test()'>查看详情</a>"
								 return str2;
							}
						}  */
			    ]]
			});
			
			//医疗卡查询
			$("#sreach-clinicid").searchbox({
				searcher:function(value){
					//alert(value);
					//访问数据源、初始化表格
					$('#mediccard-tab').datagrid({
					    url:'selectAll-clinic',
					    queryParams:{
					    	cliniccardid:value
					    },
					    pagination:true,
					    pageNumber:1,
					    pageSize:3,
					    pageList:[1,3],
					    columns:[[
					    		{field:'clinicId',title:'',width:50,checkbox:true},
					    	 	{field:'cliniccardId',title:'医疗卡号',width:160},
								{field:'clinicName',title:'病人姓名',width:110},
								{field:'clinicSex',title:'性别',width:100},
								{field:'clinicIdnumber',title:'身份证号',width:170},
								{field:'clinicRemainmoney',title:'剩余金额',width:172},
								{field:'clinicTime',title:'办卡时间',width:188,formatter:comFormatDate}
					    ]]
					});
				}
			});
			
			//充值按钮
			$(".register-addmoneys").click(function(){
				var clinic_rows =$("#mediccard-tab").datagrid('getSelected');
				if(clinic_rows == null){
					$.messager.confirm('Confirm', 
							'请点击单选框,选择充值的人！！', 
							function(r){
					});
				}else{
					//获取医疗卡号
					var cliniccar_id = clinic_rows["cliniccardId"]
					var cliniccar_userName = clinic_rows["clinicName"]
					//医疗卡主键
					var clinicid = clinic_rows["clinicId"]
					//赋值给医疗卡文本框
					$("#money-card").textbox('setValue',cliniccar_id);
					$("#clinicid").textbox('setValue',clinicid);
				    //病人姓名
				    $("#money-card-username").textbox('setValue',cliniccar_userName);
					
					//设置输入框为禁用
					$("#money-card-username").textbox('textbox').attr('readonly',true);  
					$("#money-card").textbox('textbox').attr('readonly',true);  
					
					//隐藏索引文本框
					$("#clinicid").next().hide();
					
					//打开窗口
					$("#register-addmoney-win").window('open');
				}
			});
			
			//充值提交
			$("#submit-addmoney").click(function(){
				$('#form-addmoney').form({    
				    url:'add-rechange',    
				    onSubmit: function(){    
				        // 执行验证    
				        var c=$('#form-addmoney').form("validate");
				        // return false 取消表单提交;
				        return c;
				    }, 
				    //表单提交成功之后的数据
				    success:function(data){
				    	var money1=$("#money1").textbox("getValue");
				        $(".window-tishi").text("充值成功,充值金额为:"+money1);
				    	$("#saveclinic-win").window('open');
				    	//三秒之后自动消失
					   setTimeout(function(){
					    	 $("#saveclinic-win").window('close');
						  }, 3000);
				    	 //刷新表格
				    	 $('#mediccard-tab').datagrid('reload');
				    	 //关闭窗口
				    	 $("#register-addmoney-win").window('close');
				    	 //清除文本框
				    	 $(' #form-addmoney').form('clear');
				    	 $("#money1").textbox("setValue","100");
				    }    
				}).submit();  
			});
			
			
			//医疗卡取消按钮
			$("#regist-nos").click(function(){
				$('#form-mcard').form('clear');
				$("#clinicSex option:first").prop("selected", 'selected');  
			});
			
			//医疗卡办理确定提交
			$("#regist-yess").click(function(){
				$('#form-mcard').form({    
				    url:'add-clinic',    
				    onSubmit: function(){    
				        // 执行验证    
				        var c=$('#form-mcard').form("validate");
				        // return false 取消表单提交;
				        return c;
				    }, 
				    //表单提交成功之后的数据
				    success:function(data){
				    	var money_card=$("#money-cards").val();
				    	$(".window-tishi").text("办理成功,医疗卡为:"+money_card+"");
				    	$("#saveclinic-win").window('open');
				    	//三秒之后自动消失
					    	setTimeout(function(){
					    		 $("#saveclinic-win").window('close');
					    		 $("#money-cards").val("");
						     }, 3000); 
				    	 
				    	 $('#mediccard-tab').datagrid('reload');
				         $('#form-mcard').form('clear');
					   $("#clinicSex option:first").prop("selected", 'selected');  
				    }    
				}).submit();  
				
			});
			
			//验证
			$.extend($.fn.textbox.defaults.rules, {
				    //姓名验证
					chinese: {
				        validator: function(value, param) {
				            var reg = /^[\u4e00-\u9fa5]+$/i;
				            if(reg.test(value)==true){
				            	 return reg.test(value);
				            }else{
				              $("#clinicName").textbox("setValue","");	
				            } 
				        },
				        message: "姓名请输入中文"
				    },
				    //身份证号验证
				    cradsumAge:{
				        validator: function(value, param) {
							var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
							if(reg.test(value)==true){
								 //获取身份证的的name的名字
								var inputValueName = $(this).next("input").attr("name");
								if(inputValueName == "clinicIdnumber"){
									inform_crad = this.value;//获取身份证
								}
							    //截取年计算年龄
							    var c_year=inform_crad.substring(6,10);
							    //获取系统的年份
							    var curr_time=new Date();   
								var curr_year=curr_time.getFullYear();
								//计算
							    var clinics_age = curr_year - c_year;
								console.log("clinics_age："+clinics_age);
							    
							    $.ajax({
									url:'check-idcard',
									type:'post',
									data:{
										clinic_idnumber:inform_crad
									},
									success:function(data){
										console.log("data:"+data);
										if(parseInt(data)==1){
											$(".window-tishi").text("身份证号已存在,请重新输入!");
											$("#clinicIdnumber").textbox("setValue","");
								    		$("#saveclinic-win").window('open');
									    	//三秒之后自动消失
										    setTimeout(function(){
										    	 $("#saveclinic-win").window('close');
											}, 3000);	
										}
										
										if(parseInt(data)==2){
											//赋值给年龄
										    var age = $('#uage').textbox('setValue',clinics_age);
										}
									}
								});
							    
							    return reg.test(value);
							}
				         
				        },
				        message: "请输入的正确身份证号"
				    },
				    //手机号码验证
				    telcheck:{
				    	validator:function(value,param){
				    		 var regTel=/(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
				    		 return regTel.test(value);
				    	},
				    	message:"请输入正确的手机号"
				    },
				    //地址验证
				    addresscheck:{
				    	validator: function(value, param) {
				            var addressreg = /^[\u4e00-\u9fa5]+$/i;
				            return addressreg.test(value);
				        },
				        message: "请输入正确的地址"
				    }
				    
		   });//自定义验证
			
			
		});//function

		
		//日期格式化
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();//ie火狐下都可以 
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
		
</script>
<div class="maxbox easyui-panel"  data-options="fit:true" style="border:1px solid #F3F3F4;overflow: hidden;">
	<!-- <div class="topbox" data-options="fit:true">患者信息</div> -->
	<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:990px;margin:0 auto;margin-top:25px;height:190px;">
	 <legend style="font-size:17px">患者信息</legend>
    <div class="middlebox" style="margin-top: 20px;">
       <form id="form-mcard" method="post"  >
             <div class="middle1">
				<a style="margin-left: 29px;">
					<span style="margin-right:7px;">医疗卡号</span>
					<input id="cliniccardId" name="cliniccardId" class="easyui-textbox"  data-options="width:140,height:30,required:true,readonly:true" value="${cliniccard}" >
				    <input id="money-cards"  value="${cliniccard}"  type="hidden"/>
				</a>
				
				<a style="margin-left:40px;">
				    <span style="margin-right:7px;">患者姓名</span>
					<input id="clinicName" name="clinicName" class="easyui-textbox"  data-options="width:140,height:30,required:true,validType:['chinese']">
				</a>
				
				<a  style="margin-left:40px;">
				       <span style="margin-right:7px;">性别</span>
						<span class="usexbox">
						<select  id="clinicSex" class="usex" name="clinicSex" style="width:100px; height: 30px;line-height: 30px;border-radius: 5px;">
						   <option selected="selected">男</option>
						   <option>女</option>
						</select>
						</span>
				</a>
				
				<a style="margin-left:40px;">
				   	<span style="margin-right:7px;">身份证号</span><!-- events:{blur:cradsumAge} -->
				   	<input id="clinicIdnumber" name="clinicIdnumber" class="easyui-textbox" data-options="width:140,height:30,required:true,validType:['cradsumAge']">
				</a>
			
			</div>
			<div class="middle2">
				<a style="margin-left:29px;">
					<span style="margin-right:7px;">手机号码</span><!-- events:{blur:telcheck} -->
					<input id="clinicTel" name="clinicTel" class="easyui-textbox" data-options="width:140,height:30,required:true,validType:['telcheck']">
				</a>
				
				<a style="margin-left:40px;">
				    <span style="margin-right:7px;">所在住址</span>
					<input id="uaddressinput" name="clinicAddress" class="easyui-textbox" data-options="width:140,height:30,required:true,validType:['addresscheck']">
				</a>
				
				<a style="margin-left:40px;">
				       	<span style="margin-right:7px;">年龄</span>
				        <input id="uage" name="clinicAge" class="easyui-textbox" data-options="width:100,height:30,required:true">
			
			<input type="hidden" value="${user.userName}"  name="clinicHandlename" id="clinicHandlename"> 
			
			   <p style="margin-left:78%;margin-top:30px;">
					<a id="regist-yess" class="a easyui-linkbutton" data-options="iconCls:'icon-ok',border:false"  style="margin-left:20px;" type="submit">保存</a>
					<a id="regist-nos"  class="a easyui-linkbutton"  data-options="iconCls:'icon-cancel',border:false" style="margin-left:20px;" >取消</a>
				</p>
				</div>
			</form>
    </div><!-- middlebox -->
   </fieldset>
   <!--  所有医疗卡 -->
     <div class="registeration easyui-panel" data-options="fit:true,border:false" >
     <fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:990px;margin:0 auto;margin-top:25px;height: 215px;">
	   <legend style="font-size:17px">医疗卡信息</legend>
    <!--    <div class="register-topboxs" data-options="fit:true"> -->
        
     	    <div class="register2">
	           <!--搜索框 -->
			    <div style="margin-left:20px;margin-top:5px;">
			    <a style="display:inline-block;float:left;margin-bottom:10px;">
			    <input id="sreach-clinicid" class="easyui-searchbox" style="width:200px;height:25px;" data-options="prompt:'请输入医疗卡号'"/>
			    </a>
			     <a style="display:inline-block;float:left;margin-left:67.5%" class="register-addmoneys easyui-linkbutton">医疗卡充值</a> 
			    </div>
			   
		      <div style="margin-left:20px;">    
	     	  <table id="mediccard-tab" class="easyui-datagrid" data-options="fitColumns:false,singleSelect:true,checkOnSelect:false,width:930,height:150" >
		    </table>
         </div>	
	    </div><!-- register2-->
	 </fieldset>   
      </div><!-- registeration -->
   
</div><!-- maxbox -->

<div id="register-addmoney-win" class="easyui-window" title="充值" style="width:300px;height:240px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
			<form id="form-addmoney" method="post">
				<p style="margin-left:40px;margin-top:15px;">
				         <a style="margin-right:10px;" >医疗卡号</a>
				    	<input id="money-card" name="money-card" class="easyui-textbox" data-options="width:140,height:30,required:true">
			   </p>
			   <p style="margin-left:40px;margin-top:15px;">
				         <a style="margin-right:10px;" >病人姓名</a>
				    	 <input id="money-card-username" name=" money-card-username" class="easyui-textbox" data-options="width:140,height:30,required:true">
			   </p>
			   <p style="margin-left:40px;margin-top:15px;">
				         <a style="margin-right:10px;" >充值金额</a>
				    	<input id="money1" name="rechange_money" class="easyui-textbox" data-options="width:140,height:30,required:true" value="100">
			   </p>
			         <input id="clinicid" name="clinic_id" class="easyui-textbox" >
			       
				<p>
				  <a id="submit-addmoney" style="margin-left:120px;margin-top:19px;" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>
				<p>
			</form>
</div>

<!-- 弹框提示 -->
<div id="saveclinic-win" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-tishi" style=" margin-left: 33px;font-size: 16px;margin-top: 47px;">
          </p>
</div>

</body>
</html>